import pymongo
from pandas import DataFrame


def run(source: DataFrame, param_dict: dict):
    host = param_dict["host"]
    port = param_dict["port"]
    username = param_dict["username"]
    password = param_dict["password"]
    db_name = param_dict["db"]
    collection_name = param_dict["collection"]

    client = pymongo.MongoClient(host=host, port=port, username=username, password=password)

    # 连接数据库
    db = client[db_name]
    # 连接到users集合
    collection = db[collection_name]

    for index, row in source.iterrows():
        collection.insert_one(row.to_dict())
    print("成功导入数据 = {len(source)}".format())
